<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Website_model short summary.
 *
 * Website_model description.
 *
 * @version 1.0
 * @author xianbin
 */
class Website_model extends CI_Model
{
    public $website_id;
    public $title;
    public $eng_title;
    public $imgurl;
    public $website_url;
    public $weight;
    public $website_type;
    public $menuid;

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    public function add_website($websiteModel)
    {
        return  $this->db->insert('website',$websiteModel);
    }



    public function get_website_by_id($website_id)
    {
        $sql="select * from website where website_id=$website_id";
        return $this->db->query($sql)->row();
    }

    public function update_website($websiteModel)
    {
        $sql="update website set title='$websiteModel->title',eng_title='$websiteModel->eng_title',imgurl='$websiteModel->imgurl',website_url='$websiteModel->website_url',weight='$websiteModel->weight',menuid=$websiteModel->menuid where website_id=$websiteModel->website_id";
        return $this->db->query($sql);
    }

    public function del_website($website_id)
    {
        $sql="delete from website where website_id=$website_id";
        return $this->db->query($sql);
    }

    public function get_all_website_by_type($type)
    {
        $sql="select * from website where website_type=$type oder by weight desc";
        return $this->db->query($sql)->result();
    }

    public function get_website_by_type_weight($type,$weight)
    {
        $sql="select * from website where website_type=$type and weight=$weight";
        return $this->db->query($sql)->row();
    }

    public function get_website_by_id_weight($website_id,$weight)
    {
        $sql="select * from website where website_id=$website_id and weight=$weight";
        return $this->db->query($sql)->row();
    }
}